package com.client;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.cxf.jaxws.endpoint.dynamic.JaxWsDynamicClientFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLOutput;
import java.util.Scanner;

@Controller
public class Client {

    private static final String wsdlUrl = "http://127.0.0.1:8093/webService/testWebService?wsdl";
    private static final String operationName = "docs";
//    private static final Object[] params = new Object[]{"喵的还有谁....", "拿捏。。。","你打野"};
//      private static final Object[] user= new Object[]{"forlove"};



    public static void main(String[] args) {
        //创建动态客户端
        JaxWsDynamicClientFactory dcf = JaxWsDynamicClientFactory.newInstance();
        org.apache.cxf.endpoint.Client client = dcf.createClient(wsdlUrl);
        //添加发送请求拦截器
        client.getOutInterceptors().add(new ClientInterceptor("root", "123456"));
          while (true) {
              Scanner scanner = new Scanner(System.in);
              String user = scanner.next();
              System.out.println("请输入用户名查看个人所属文件信息");

          try {
//            Object[] response = client.invoke(operationName, params);
              Object[] response = client.invoke(operationName, user);

              System.out.println("返回数据:" + JSONObject.parse(JSON.toJSONString(response[0])));
//            System.out.println("返回数据:" + JSONObject.parse(JSON.toJSONString(response[1])));
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
    }
}